package jt.classic.system.workflow.impl;

import jt.classic.system.workflow.WInner;
import jt.classic.system.workflow.WInnerHandler;
import jt.classic.system.workflow.WorkflowException;

import org.limp.basework.AbstractSimpleBean;

import org.limp.mine.StringTool;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 内部流转接口实现类
 *
 * @author bizkit
 *
 */
public class WInnerImpl extends AbstractSimpleBean implements WInner {
    private final static String DEFAULT_HANDLER = "jt.classic.system.workflow.impl.DefaultWInnerHandler";
    private List list;
    private String memo;
    private int inner;
    private String handleName;

    public List ipart() {
        // TODO Auto-generated method stub
        return this.list;
    }

    public String imemo() {
        // TODO Auto-generated method stub
        return this.memo;
    }

    public int inner() {
        // TODO Auto-generated method stub
        return this.inner;
    }

    public WInnerHandler ihandler() throws WorkflowException {
        WInnerHandler handler = null;

        if (handler == null) {
            try {
                if (StringTool.checkString(this.handleName).equals("")) {
                    handler = (WInnerHandler) Class.forName(DEFAULT_HANDLER)
                                                   .newInstance();
                } else {
                    handler = (WInnerHandler) Class.forName(this.handleName.trim())
                                                   .newInstance();
                }
            } catch (Exception ex) {
                throw new WorkflowException("get inner handler error.", ex);
            }

            Map map = new HashMap();
            map.put("INNER", this);

            handler.reload(map);
        }

        return handler;
    }

    public void reload(Map info) {
        this.info = info;

        this.list = (List) info.get("PARTS");
        this.memo = (String) info.get("MEMO");
        this.inner = Integer.parseInt((String) info.get("INNER"));
        this.handleName = (String) info.get("HANDLER");
    }
}
